package com.xuecheng.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class ElasticSearchConfig {

    @Value("${xuecheng.elasticsearch.hostlist}")
    private String hostlist;
    //创建client对象，存入容器
    @Bean
    public RestHighLevelClient restHighLevelClient () {
        HttpHost httpHost = HttpHost.create(hostlist);
        return new RestHighLevelClient(RestClient.builder(httpHost));
    }
}
